package com.my.dao;

import com.my.pojo.Stock;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


@Repository
public interface StockDao extends JpaRepository<Stock, Integer>, JpaSpecificationExecutor<Stock> {

    @Query(value = "SELECT s.*, b.business_id FROM (stock AS s) JOIN (goods as g) ON s.goods_id = g.goods_id JOIN (business as b) ON g.business_id = b.business_id " +
            "where b.business_id = ?2 and s.info like %?1% order by ?#{#pageable}", nativeQuery = true)
    Page<Stock> queryByStock(String context, Integer businessId, Pageable pageable);

}
